<?php
class addon
{
	public static function getImdbUrl($imdb_id)
	{
		if(empty($imdb_id))
		{
			return '';
		}
		if(stripos($imdb_id,"tt")!==false)
		{
			$imdb_id = str_replace('tt','',$imdb_id);
		}
		return("http://www.imdb.com/title/tt".$imdb_id."/");
	}

	
	public static function getMovieDoubanUrl($douban_id)
	{
		if(empty($douban_id))
		{
			return '';
		}
		return("http://movie.douban.com/subject/".$douban_id."/");
	}
	
	public static function getMovieSubjectUrl($douban_id)
	{
		if(empty($douban_id))
		{
			return '#';
		}
		return("http://movie.doubanxia.com/subject/".$douban_id."/");
	}

	public static function convertByteToIec($size_B)
	{
		$iec_array = array('B','KiB','MiB','GiB','TiB');

		$iec_num = floatval($size_B);

		for($i=0;$iec_num>1024;$i++)
		{

			$iec_num = $iec_num/1024;
		}
		if($i>=3)
		{
			$iec_num = number_format($iec_num, 2, '.', '');
		}
		else
		{
			$iec_num = number_format($iec_num, 0, '.', '');
		}
		return $iec_num.$iec_array[$i];
	}

	public static function getIecSizeByEd2k($ed2k)
	{
		if(is_array($ed2k))
		{
			foreach($ed2k as $value)
			{
				$a = explode('|',$value);
				$size_B = $a[3];
				$iec_size[] = self::convertByteToIec($size_B);
				//$data['file_name'] = urldecode($a[2]);
			}
		}
		else
		{
			$a = explode('|',$ed2k);
			$size_B = $a[3];
			$iec_size = self::convertByteToIec($size_B);
		}
		return $iec_size;
	}
	
	
	
	/*public static function convertByteToSi1000(size_B)
	{
		var si1000_array = new Array('B','KB','MB','GB','TB');
		var si1000_num = parseFloat(size_B);
		for(var i=0;si1000_num>1000;i++)
		{
			si1000_num = si1000_num/1000;
		}
		if(i>=3)
		{
			si1000_num = si1000_num.toFixed(2);
		}
		else
		{
			si1000_num = si1000_num.toFixed(0);
		}
		return si1000_num+" "+si1000_array[i];
	}*/
	public static function secondToHourArray($second)
	{
		if(empty($second))
		{
			return '0';
		}
		$hour_array['hour'] = intval($second/3600);
		$hour_array['minute'] = intval(($second%3600)/60);
		$hour_array['second'] = $second%60;
		return $hour_array;
	}
}
?>
